/*
 * 主文件
 * @Author: ljb
 * @Date: 2018-11-13 15:14:43
 * @Last Modified by: kanglin
 * @Last Modified time: 2019-03-05 11:10:03
 */
import '@babel/polyfill';
import Vue from 'vue';
import VueRouter from 'vue-router';
import VueLazyLoad from 'vue-lazyload';
import toast from 'cube-ui/lib/toast';
import 'cube-ui/lib/cube.min.css';
import axios from 'src/utils/axios-interceptors';

import InfiniteLoading from 'vue-infinite-loading';

import { formatUrl } from 'src/utils/utils';
import { i18n, $t } from 'src/i18n/index';
import router from './router';
import store from './vuex/store';

/* eslint-disable  */
import './assets/css/common.css';
/* eslint-enable  */
import App from './app.vue';

Vue.use(InfiniteLoading, {
	slots: {
		// noMore
		noMore: $t('common.no_more_data'),
	},
});

/* @see https://www.npmjs.com/package/vue-lazyload#css-state */
Vue.use(VueLazyLoad);

Vue.use(VueRouter);

Vue.use(toast);

let android_param = {};

/* eslint-disable */
// 安卓注入的全局参数
try {
	const param_str = DIREWOLF.getConfig();
	android_param = JSON.parse(param_str);
} catch (error) {
	console.log(error);
}
/* eslint-enable */

const DEFAULT_LANG = 'zh-cn';	// 默认语言
const DEFAULT_STORE = 0;	// 默认店铺
const DEFAULT_CURRENCY = 'CNY'; // 货币

const url_param = formatUrl();

if (url_param.language || url_param.lang) {
	url_param.language = url_param.language || url_param.lang; // 把 lang 赋给 language
} else {
	url_param.language = android_param.language || DEFAULT_LANG;
}
if (!url_param.currency) url_param.currency = android_param.currency || DEFAULT_CURRENCY;
if (!url_param.store_id) url_param.store_id = android_param.store_id || DEFAULT_STORE;


Vue.prototype.$url = url_param;	// 将网址参数对象注入到vue的prototype，方便使用
Vue.prototype.$http = axios;

function initProject() {
	return new Vue({
		el: '#app',
		i18n,
		router,
		store,
		render: h => h(App),
	});
}

initProject();
